Introduction
This lab is a short one. It reviews simple linear regression. There are six questions to answer concerning seed germination.
The main emphasis of the lab is interpretation.
In this introduction I will emphasize the Bayesian methodology. You should understand both paradigms but be most conversant with the classical.
The data
The data comes from that supplied with the 5th edition of the book.
We will use a loess smoother to help understand the nature of the trend within the data. We will also use the plotly package to convert the ggplot to a plotly enhanced graphic so that on hover we can detect unusual points.
g <- ggplot(seed, aes(x = TEMP, y = CHANGE ))
g <- g + geom_point() + stat_smooth(method = "loess", formula = y ~ x)
ggplotly(g)Interpretation of plot
The point corresponding to TEMP = 301 is away from the trend and likely an outlier. Otherwise the trend looks straight line and hence a SLR model would be appropriate after the 5th point is removed.
Bayesian analysis
We will use MCMCpack to create a sample from the posterior.
We will examine the histograms of the samples to see if the distributions have likely reached stationarity. Also we will inspect the plots to understand the skewness and modality of the distributions.
library(ggmcmc)
library(MCMCpack)
which(seed$TEMP==301.0)
ws#> [1] 5
seedn <- seed[-5,]
postn <-MCMCregress(formula = CHANGE ~ TEMP,data = seedn, burnin = 1000, mcmc = 10000,thin = 1)
s <- ggs(postn)
ggs_histogram(s)sm <- summary(postn)
sm
ws#>
ws#> Iterations = 1001:11000
ws#> Thinning interval = 1
ws#> Number of chains = 1
ws#> Sample size per chain = 10000
ws#>
ws#> 1. Empirical mean and standard deviation for each variable,
ws#> plus standard error of the mean:
ws#>
ws#> Mean SD Naive SE Time-series SE
ws#> (Intercept) 139.9011 11.8857 0.118857 0.1195171
ws#> TEMP -0.4502 0.0407 0.000407 0.0004092
ws#> sigma2 0.1365 0.2268 0.002268 0.0035466
ws#>
ws#> 2. Quantiles for each variable:
ws#>
ws#> 2.5% 25% 50% 75% 97.5%
ws#> (Intercept) 117.04467 133.53061 139.82870 146.0337 163.8651
ws#> TEMP -0.53252 -0.47113 -0.44994 -0.4284 -0.3720
ws#> sigma2 0.02517 0.05147 0.08264 0.1424 0.5884The plots are in alphabetical order, and show symmetrical well formed uni-modal distributions for the beta parameters and a typical right skewed distribution for the variance.
Equation of the estimating trend
From the means of the sample distributions we obtain the Bayesian point estimates
\[ \widehat{CHANGE} = 139.9010764 -0.4501684 TEMP \]
Finally
With this brief introduction you may now start on the lab